package com.my.myrecorder.PlayAduio;

import android.media.MediaPlayer;
import android.util.Log;

import java.io.IOException;

/**
 * Created by 张英杰 on 2016/10/14.
 */
public class UPlayer implements IVoiceManager {
    private final String TAG = UPlayer.class.getName();
    private String path;

    private MediaPlayer mPlayer;

    public UPlayer( String path) {
        this.mPlayer = new MediaPlayer();
        this.path = path;
    }

    @Override
    public boolean start() {
        try {
            //设置要播放的文件
            mPlayer.setDataSource(path);
            mPlayer.prepare();
            //播放
            mPlayer.start();
        } catch (IOException e) {
            e.printStackTrace();
            Log.e(TAG, "===prepare() failed");
        }
        return false;
    }

    @Override
    public boolean stop() {
        mPlayer.stop();
        mPlayer.release();
        mPlayer = null;
        return false;
    }
}

interface IVoiceManager {

    public boolean start();
    public boolean stop();
}